package 几个重要的接口;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-07-02
 * Time: 0:27
 */
class Person implements Cloneable{
    public int age = 10;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
}
public class Test1 {
    public void fun() throws CloneNotSupportedException {
        //Person person = new Person();
        Person person1 = (Person) super.clone();//直接调用object类的clone 但是没有明确克隆谁 所以会报错

        System.out.println(person1);
    }
    public static void main2(String[] args) throws CloneNotSupportedException {
        Test1 test1 = new Test1();
        test1.fun();

    }
    //深拷贝
    public static void main1(String[] args) throws CloneNotSupportedException {
        Person person = new Person();
        Person person1 = (Person) person.clone();
        System.out.println(person);
        System.out.println(person1);
        System.out.println("================");
        System.out.println(person.age);
        System.out.println(person1.age);
        System.out.println("=========修改后=========");
        person1.age = 100;
        System.out.println(person.age);
        System.out.println(person1.age);
    }

}
